﻿' ------------------------------------------------------------------------------
' A LogForm is a form that displays a LogControl. When closed, the form
' hides inself instead of closing so the contents of the log are preserved.
' This form also resizes/moves to "attach" itself to the right hand side
' of the main application window when it's visibility changes.
' ------------------------------------------------------------------------------
' This file is part of the SQL Server 2008 Technology Demonstration. This
' application was designed and coded by Eric Weitzman, LandTime Inc, for
' Microsoft Corporation. Contact Ed Katibah at Microsoft about this demo.
' Copyright © 2008 Microsoft Corporation. All rights reserved.
' ------------------------------------------------------------------------------

Public Class LogForm

    Public WriteOnly Property UpdateFrequently() As Boolean
        Set(ByVal value As Boolean)
            LogControl1.UpdateFrequently = value
        End Set
    End Property

    Private Sub LogForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.Hide()
        e.Cancel = True
        LogControl1.Log = False
    End Sub

    Private Sub LogForm_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        LogControl1.Log = Me.Visible
        If Not Visible Then Return

        Dim maxwidth As Integer = My.Computer.Screen.Bounds.Right - (g_mainform.DesktopLocation.X + g_mainform.Width)
        Me.SetDesktopBounds(g_mainform.DesktopLocation.X + g_mainform.Width, _
                            g_mainform.DesktopLocation.Y, _
                            Math.Min(Me.Width, maxwidth), _
                            g_logwindow.Height)

    End Sub
End Class